package com.alks.function.service.impl.chengKong;

import com.alks.common.aop.AutoPageAop;
import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.common.data.thread.UserIdThread;
import com.alks.common.utils.MinIoUtil;
import com.alks.common.utils.UserInfoUtil;
import com.alks.common.utils.beanutils.BeanUtil;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.page.PageRecord;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.entity.exception.ServiceErrorException;
import com.alks.function.data.dto.chengKong.assort.*;
import com.alks.function.data.dto.procurement.NotOrderDetailsDto;
import com.alks.function.data.request.chengKong.*;
import com.alks.function.mapper.chengKong.GeneralMaterialsMapper;
import com.alks.function.mapper.chengKong.LargeCargoUsageMapper;
import com.alks.function.mapper.chengKong.RAndDUsageMapper;
import com.alks.function.mapper.procurement.SporadicClearanceMapper;
import com.alks.function.service.chengKong.GeneralMaterialsService;
import com.alks.function.service.chengKong.MaterialManagementService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class GeneralMaterialsServiceImpl implements GeneralMaterialsService {

    @Autowired
    private MaterialManagementService materialManagementService;

    @Resource
    private RAndDUsageMapper rAndDUsageMapper;

    @Resource
    private LargeCargoUsageMapper largeCargoUsageMapper;

    @Resource
    private SporadicClearanceMapper sporadicClearanceMapper;

    /**
     * 成型材料建档列表
      * @return
     */
    @Override
    public ResponseInfo getGeneralMaterialsList() {

        //分类资料列表
        List<YfMtlTypeNewDto> nodeList = materialManagementService.getAssortList();

        //拿到包装资料的树结构
        List<YfMtlTypeNewDto> uNodes = nodeList.stream()
                .filter(node -> node.getTypeNo().equals("U"))
                .collect(Collectors.toList());

        //获取粘剂类的树结构
        List<YfMtlTypeNewDto> mNodes = nodeList.stream()
                .filter(node -> node.getTypeNo().equals("M"))
                .collect(Collectors.toList());
        uNodes.addAll(mNodes);

        return ResponseInfo.ok(uNodes);
    }

    @Resource
    private GeneralMaterialsMapper generalMaterialsMapper;

    /**
     *通用材料建档
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getGeneralMaterialsAdd(CacheAddRequest request) {

        if (StringUtils.isEmpty(request.getMtlNo())) {
            return ResponseInfo.error("请选择中类!");
        }

        if (StringUtils.isEmpty(request.getMtlName())) {
            return ResponseInfo.error("材料名称不能为空!");
        }

        if (StringUtils.isEmpty(request.getMtlUnit())) {
            return ResponseInfo.error("单位不能为空!");
        }

        YfMaterial yfMaterial = new YfMaterial();
        BeanUtil.copyProperties(request, yfMaterial);

        //查询编码
        Set<String> mtlNoList = generalMaterialsMapper.getMtlNoList(request.getMtlNo());
        //初始化num
        String num = "";
        boolean containsAllNumbers = true;
        if (mtlNoList.size() == 0) {

            //设置编码
            num = String.format("%05d", 1);
            num = request.getMtlNo() + num;
            yfMaterial.setMtlNo(num);
        } else {
            for (int i = 1; i < 100000; i++) {
                //生成5位数
                num = String.format("%05d", i);
                num = request.getMtlNo() + num;
                //集合中不包含跳出
                if (!mtlNoList.contains(num)) {
                    containsAllNumbers = false;
                    break;
                }
            }
            if (containsAllNumbers) {
                return ResponseInfo.error("物料编码已到添加上限,请联系管理员!");
            }
        }


        //获取公司用户名
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();
        String companyId = dto.getCompanyId();

        yfMaterial.setMtlType(request.getMtlNo());
        yfMaterial.setSysDate(new Date());
        yfMaterial.setSysUser(userName);
        yfMaterial.setCompanyId(companyId);

        //添加
        generalMaterialsMapper.AddGeneralMaterials(yfMaterial);

        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 材料查询列表
     * @param request
     * @return
     */
    @Override
    @AutoPageAop
    public ResponseInfo getMaterialQueryList(MaterialQueryRequest2 request) {

        Map map = new HashMap();

        //查询
        List<YfMaterialDto> materialQueryList = generalMaterialsMapper.getMaterialQueryList(request);

        //获取total
        PageInfo list = new PageInfo(materialQueryList);

        map.put("materialQueryList", materialQueryList);
        map.put("total", list.getTotal());

        return ResponseInfo.ok(map);
    }

    /**
     * 材料查询修改
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getMaterialUpdate(YfMaterialUpdateRequest request) {

        if (StringUtils.isEmpty(request.getMtlNo())){
            return ResponseInfo.error("编码为空不能修改!");
        }

        //获取用户名
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();

        YfMaterial yfMaterial = new YfMaterial();
        BeanUtil.copyProperties(request,yfMaterial);
        yfMaterial.setSysDate(new Date());
        yfMaterial.setSysUser(userName);

        generalMaterialsMapper.updateMaterial(yfMaterial);

        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 材料查询删除
     * @param mtlNo
     * @return
     */
    @Override
    public ResponseInfo getMaterialDel(String mtlNo) {
        if (StringUtils.isEmpty(mtlNo)) return ResponseInfo.error("参数错误!");

        //删除
        generalMaterialsMapper.delMaterialDel(mtlNo);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 正式材料明细
     * @param request
     * @return
     */
    @Override
    @AutoPageAop
    public ResponseInfo getPublicMaterials(CommonQueryRequest request) {

        Map map = new HashMap();

        //查询
        List<YfBomMtlListDto> yfBomMtlList = generalMaterialsMapper.PublicMaterialsList(request);

        //获取total
        PageInfo list = new PageInfo(yfBomMtlList);

        map.put("materialQueryList", yfBomMtlList);
        map.put("total", list.getTotal());
        return ResponseInfo.ok(map);
    }

    @Override
    @AutoPageAop
    public ResponseInfo getPublicMaterials2(CommonQueryRequest request) {
        //查询通用材料（公共材料）
        List<YfBomMtlListDto> commonMaterialDetailList = generalMaterialsMapper.PublicMaterialsList(request);

        // 待订购明细已存在的数据
        String companyId = UserIdThread.get().getCompanyId();
        String loginName = UserIdThread.get().getLoginName();
        List<NotOrderDetailsDto> notOrderDetailsList = sporadicClearanceMapper.getNotOrderDetailsList(companyId,loginName);

        if (com.alks.common.utils.beanutils.ObjectUtils.isNotEmpty(notOrderDetailsList)) {
            // 已经存在的 mtlNo 集合
            Set<String> mtlNoSet = notOrderDetailsList.stream()
                    .map(NotOrderDetailsDto::getMtlNo)
                    .collect(Collectors.toSet());

            if (com.alks.common.utils.beanutils.ObjectUtils.isNotEmpty(commonMaterialDetailList)) {
                for (YfBomMtlListDto dto : commonMaterialDetailList) {
                    if (mtlNoSet.contains(dto.getMtlNo())) {
                        dto.setFlag("Y");
                    }
                }
            }
        }

        //获取total
        Map map = new HashMap();
        PageInfo list = new PageInfo(commonMaterialDetailList);
        map.put("lotNoList", commonMaterialDetailList);
        map.put("total", list.getTotal());
        return ResponseInfo.ok(map);
    }

    /**
     * 正式材料明细修改
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getPublicMaterialsUpdate(CommonUpdateRequest request) {

        if (StringUtils.isEmpty(request.getMtlNo())) {
            return ResponseInfo.error("编码为空不能修改!");
        }

        YfBomMtl yfBomMtl = new YfBomMtl();

        //拿到用户
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();

        //0设置为Y否则就是null
        if (request.getPublicFlag().equals("0")) {
            yfBomMtl.setPublicFlag("Y");
        }

        yfBomMtl.setMtlNo(request.getMtlNo());
        yfBomMtl.setSafetyQty(request.getSafetyQty());
        yfBomMtl.setSysDate(new Date());
        yfBomMtl.setSysUser(userName);

        //修改
        generalMaterialsMapper.updatePublicMaterials(yfBomMtl);

        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 新增作业
     * @param
     * @return
     */
    @Override
    public ResponseInfo getStyleAdd(Map<String, String> map) {

        //获取值
        String styleNo = map.get("styleNo");

        if (StringUtils.isEmpty(styleNo)) {
            return ResponseInfo.error("请输入型体!");
        }

        //查询型体是否存在
        String styleCode = generalMaterialsMapper.getStyleNo(styleNo);
        if (!StringUtils.isEmpty(styleCode)) {
            return ResponseInfo.error("型体已存在,不能新增!");
        }

        //获取用户名
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();
        String companyId = dto.getCompanyId();

        YfStyle yfStyle = new YfStyle();
        yfStyle.setStyleNo(styleNo);
        yfStyle.setTechPerson(userName);
        yfStyle.setCompanyId(companyId);
        yfStyle.setSysUser(userName);
        yfStyle.setSysDate(new Date());

        //保存
        generalMaterialsMapper.AddStyle(yfStyle);

        return ResponseInfo.ok("操作成功!");
    }

    //图片上传
    @Resource
    MinIoUtil minIoUtil;

    /**
     * 保存
     * @param request
     * @return
     */
    @Override
    @Transactional
    public ResponseInfo getStyleBasicAdd(StyleAddRequest request) {

        //获取公司
        SysUserTokenDTO dto = UserIdThread.get();
        String companyId = dto.getCompanyId();

        if (StringUtils.isEmpty(request.getStyleNo())) {
            return ResponseInfo.error("型体为空不能保存!");
        }

        if (StringUtils.isEmpty(request.getSizeType()) && !StringUtils.isEmpty(request.getBaseSize())) {
            return ResponseInfo.error("码制不能为空!");
        }

        //判断基本码是否存在
        if (!StringUtils.isEmpty(request.getSizeType())&&!StringUtils.isEmpty(request.getBaseSize())) {

            //根据公司和名字查询
            List<PcLotSizeSeqDto> pcLotSizeSeqList = generalMaterialsMapper.getSizeTypeByName(request.getSizeType(), companyId);
            if (pcLotSizeSeqList == null || pcLotSizeSeqList.size() == 0) {
                return ResponseInfo.error("码制不存在!");
            }

            //检查元素是否存在
            boolean exists = pcLotSizeSeqList.stream()
                    .anyMatch(pcLotSizeSeq -> pcLotSizeSeq.getSizeNo().equals(request.getBaseSize()));

            if (!exists) {
                return ResponseInfo.error("基本码不存在!");
            }
        }

        YfStyle yfStyle = new YfStyle();
        BeanUtil.copyProperties(request, yfStyle);

        //获取用户名
        String userName = dto.getUserName();
        yfStyle.setSysUser(userName);
        yfStyle.setSysDate(new Date());

        //修改基本信息
        generalMaterialsMapper.updateStyle(yfStyle);
        //制具资料
        if (request.getTypeList() != null) {

            //删除制具资料信息
            generalMaterialsMapper.delStyleType(request.getStyleNo());

            //copy值
            YfStyleType yfStyleType = new YfStyleType();
            BeanUtil.copyProperties(request.getTypeList(), yfStyleType);
            yfStyleType.setCompanyId(companyId);
            yfStyleType.setStyleNo(request.getStyleNo());

            //新增
            generalMaterialsMapper.AddStyleType(yfStyleType);
        } else {
            //删除
            generalMaterialsMapper.delStyleType(request.getStyleNo());
        }

        //配码资料
        if (request.getNumberList() != null && !request.getNumberList().isEmpty()) {

            //删除之前数据
            generalMaterialsMapper.delStyleSize(request.getStyleNo());

            //添加
            generalMaterialsMapper.addStyleNumber(
                    request.getNumberList(),
                    companyId,
                    request.getTypeList().getTypeNo(),
                    request.getStyleNo());
        } else {
            //如果为空删除配码资料
            generalMaterialsMapper.delStyleSize(request.getStyleNo());
        }

        //型体配色资料
        if (!ObjectUtils.isEmpty(request.getPhotoList())) {
            boolean hasDuplicates = request.getPhotoList().stream()
                    .map(StylePhotoRequest::getStyleColor)
                    .collect(Collectors.toSet())
                    .size() < request.getPhotoList().size();

            if (hasDuplicates) {
                throw new ServiceErrorException("存在相同颜色!");
            }

            //地址处理
            List<YfStyleColorDetail> photoList = request.getPhotoList().stream().map(s -> {
                if (ObjectUtils.isEmpty(s.getStyleColor())){
                    throw new ServiceErrorException("颜色为空!");
                }
                YfStyleColorDetail detail = new YfStyleColorDetail();
                BeanUtil.copyProperties(s, detail);

                //设置公司
                detail.setCompanyId(companyId);
                //设置型体
                detail.setStyleNo(request.getStyleNo());
                detail.setSysUser(dto.getLoginName());
                return detail;
            }).collect(Collectors.toList());

            //删除型体配色资料
            delStyleColor(request);
            //插入
            generalMaterialsMapper.AddStyleColorPhoto(photoList);
        } else {
            //删除型体配色资料
            delStyleColor(request);
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 删除颜色
     * @param request
     */
    private void delStyleColor(StyleAddRequest request) {
        generalMaterialsMapper.delStyleColor(request.getStyleNo());
    }

    /**
     * 取号码
     * @param map
     * @return
     */
    @Override
    public ResponseInfo getStyleNumber(Map<String, String> map) {

        //获取值
        String sizeType = map.get("sizeType");
        String sizeCode = map.get("sizeCode");
        if (StringUtils.isEmpty(sizeType)) {
            return ResponseInfo.error("型体基本资料码值为空!");
        }

        if (StringUtils.isEmpty(sizeCode)) {
            return ResponseInfo.error("参数不能为空!");
        }

        //查询码制号码信息
        List<PcLotSizeSeqDto> sizeTypeByName = generalMaterialsMapper.getSizeTypeByName2(sizeType, UserIdThread.get().getCompanyId(),sizeCode);
        return ResponseInfo.ok(sizeTypeByName);
    }

    /**
     * 取号码插入
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getStyleNumberAdd(StyleNumberAddRequest request) {

        if (StringUtils.isEmpty(request.getStyleNo())) {
            return ResponseInfo.error("型体为空不能添加!");
        }
        if (request.getTypeNo() == null) {
            return ResponseInfo.error("制具序号为空!");
        }

        if (request.getNumberList() == null || request.getNumberList().size() == 0) {
            return ResponseInfo.error("请选择记录!");
        }

        generalMaterialsMapper.delStyleSize(request.getStyleNo());
        //保存
        generalMaterialsMapper.addStyleNumber(
                request.getNumberList(),
                UserIdThread.get().getCompanyId(),
                request.getTypeNo(),
                request.getStyleNo());

        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 基本资料查询
     * @param request
     * @return
     */
    @Override
    @AutoPageAop
    public ResponseInfo getStyleBasicList(StyleBasicRequest request) {
        PageRecord<YfStyle2TypeDto> pageRecord = new PageRecord<>();
        //获取用户名
        String userName = UserIdThread.get().getUserName();
        //查询基本资料与制具资料
        List<YfStyle2TypeDto> styleBasicList = generalMaterialsMapper.getStyleBasicList(request, userName);
        //设置颜色代码
        List<YfStyle2TypeDto> dtoList = styleBasicList.stream().map(s -> {
            if (s != null && s.getBackgroundColor() != null && !s.getBackgroundColor().isEmpty()) {
                if (s.getBackgroundColor().equals("Y")) {
                    s.setBackgroundColor("#40FF80");
                }
            }
            return s;
        }).collect(Collectors.toList());
        PageInfo list = new PageInfo(styleBasicList);
        pageRecord.setList(dtoList);
        pageRecord.setTotal(list.getTotal());
        return ResponseInfo.ok(pageRecord);
    }

    /**
     * 获取制具资料
     * @param styleNo
     * @return
     */
    @Override
    public ResponseInfo getStyleType(String styleNo) {
        SdStyleType styleType = generalMaterialsMapper.getStyleType(styleNo);
        return ResponseInfo.ok(styleType);
    }

    /**
     * 配码资料查询
     * @param map
     * @return
     */
    @Override
    public ResponseInfo getStyleSizeList(Map<String, String> map) {

        String styleNo = map.get("styleNo");
        String typeNo = map.get("typeNo");

        //查询配码资料
        List<YfStyleSizeDto> styleSizeList = generalMaterialsMapper.getStyleSizeList(styleNo, typeNo);

        return ResponseInfo.ok(styleSizeList);
    }

    /**
     * 型体配色资料查询
     * @param map
     * @return
     */
    @Override
    public ResponseInfo getStylePhotoList(Map<String,String> map) {
        String styleNo = map.get("styleNo");
        //型体配色资料查询
        List<SdStyleColorDto> stylePhotoList = generalMaterialsMapper.getStylePhotoList(styleNo);
        return ResponseInfo.ok(stylePhotoList);
    }

    /**
     * 复制
     * @param request
     * @return
     */
    @Override
    @Transactional
    public ResponseInfo getStyleBasicCopyAdd(StyleAddRequest request) {
        if (StringUtils.isEmpty(request.getStyleNo())) {
            return ResponseInfo.error("请输入目标型体!");
        }

        //查询型体是否存在
        String style = generalMaterialsMapper.getStyleNo(request.getStyleNo());
        if (!StringUtils.isEmpty(style)) {
            return ResponseInfo.error("目标型体已存在，不能复制!");
        }
        if (!StringUtils.isEmpty(style)&&request.getStyleNo().equals(style)) {
            return ResponseInfo.error("原型体与目标型体相同，不能复制!");
        }

        YfStyle yfStyle = new YfStyle();
        BeanUtil.copyProperties(request, yfStyle);

        //获取用户名
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();
        String companyId = dto.getCompanyId();
        yfStyle.setSysUser(userName);
        yfStyle.setSysDate(new Date());
        yfStyle.setCompanyId(companyId);
        yfStyle.setTechPerson(userName);
        yfStyle.setSeason("");
        yfStyle.setShoeType("");

        //保存基本资料
        generalMaterialsMapper.AddStyle(yfStyle);

        //保存制具资料
        if (request.getTypeList() != null&& request.getTypeList().getTypeNo()!=null) {

            //copy值
            YfStyleType yfStyleType = new YfStyleType();
            BeanUtil.copyProperties(request.getTypeList(), yfStyleType);
            yfStyleType.setCompanyId(companyId);
            yfStyleType.setStyleNo(request.getStyleNo());
            yfStyleType.setMidsole("");
            yfStyleType.setItemName("");
            yfStyleType.setSeqNo1(null);
            yfStyleType.setSeqNo2(null);
            yfStyleType.setSize1("");
            yfStyleType.setSize2("");

            //删除制具资料信息
            generalMaterialsMapper.delStyleType(request.getStyleNo());
            //新增
            generalMaterialsMapper.AddStyleType(yfStyleType);
        }
        //保存配码资料
        if (request.getNumberList() != null && !request.getNumberList().isEmpty()) {

            //删除之前数据
            generalMaterialsMapper.delStyleSize(request.getStyleNo());
            //添加
            generalMaterialsMapper.addStyleNumber(
                    request.getNumberList(),
                    companyId,
                    request.getTypeList().getTypeNo(),
                    request.getStyleNo());
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 整单删除
     * @param map
     * @return
     */
    @Override
    @Transactional
    public ResponseInfo getStyleBasicAllDel(Map<String, String> map) {
        String styleNo = map.get("styleNo");
        if (styleNo.isEmpty()) {
            return ResponseInfo.error("参数不能为空!");
        }
        String flag = generalMaterialsMapper.getCheckUp(styleNo);
        if ("Y".equals(flag)){
            return ResponseInfo.error("该型体已检核,不能删除!");
        }
        //判断是否被研发用量引用
        Integer bomIsExist = generalMaterialsMapper.getBomIsExist(styleNo);
        if (bomIsExist!=null && bomIsExist!=0){
            return ResponseInfo.error("型体已关联BOM资料,不能整单删除!");
        }
        generalMaterialsMapper.delStyleBasic(styleNo);
        generalMaterialsMapper.delStyleType(styleNo);
        generalMaterialsMapper.delStyleSize(styleNo);
        generalMaterialsMapper.delStyleColor(styleNo);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 制单员变更
     * @param map
     * @return
     */
    @Override
    public ResponseInfo getChangeOfOrderMaker(Map<String, String> map) {

        String styleNo = map.get("styleNo");
        String techPerson = map.get("techPerson");

        if (StringUtils.isEmpty(styleNo) || StringUtils.isEmpty(techPerson)) {
            return ResponseInfo.error("请选择制单员!");
        }

        YfStyle yfStyle = new YfStyle();

        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();
        yfStyle.setSysUser(userName);
        yfStyle.setSysDate(new Date());
        yfStyle.setStyleNo(styleNo);
        yfStyle.setTechPerson(techPerson);

        //修改
        generalMaterialsMapper.updateStyle2TechPerson(yfStyle);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 检验0/1取消检验
     * @param styleNoList
     * @param choose
     * @return
     */
    @Override
    public ResponseInfo getInspect(List<String> styleNoList, Integer choose) {

        if (styleNoList == null || styleNoList.isEmpty()) {
            return ResponseInfo.error("请选择记录!");
        }

        if (choose == 0) {
            //获取用户名
            SysUserTokenDTO dto = UserIdThread.get();
            String userName = dto.getUserName();
            //检验状态
            String cfmFlag = "Y";
            generalMaterialsMapper.updateStyle2Inspect(styleNoList, new Date(), userName, cfmFlag);
        } else {
            generalMaterialsMapper.updateStyle2Inspect(styleNoList, null, null, null);
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 上传图片
     *
     * @param file
     * @param path
     * @return
     */
    @Override
    public ResponseInfo updateStylePhoto(MultipartFile file, String path) {

        if (null==file || 0 == file.getSize()){
            log.error("上传文件不能为空!");
            return ResponseInfo.error("上传文件不能为空!");
        }
        //生成图片名称
        String photoPath = UUID.randomUUID().toString();
        photoPath = "/photo/profile/yfcostcolor/"+photoPath+".jpg";
        //第一个参数为文件
        // 第二个参数为桶
        // 第三个是图片路径
        minIoUtil.upload(file,"photo",photoPath);
        photoPath="http://192.168.1.220:9000/photo"+photoPath;
        if (!StringUtils.isEmpty(path)){
            minIoUtil.removeObject("photo",path);
        }
        Map map=new HashMap();
        map.put("photoPath",photoPath);
        return ResponseInfo.ok(map,"上传成功!");
    }

    /**
     * 型体配色添加
     * @param styleColorDetail
     * @return
     */
    @Override
    public ResponseInfo getStylePhotoAdd(YfStyleColorDetail styleColorDetail) {
        if (ObjectUtils.isEmpty(styleColorDetail.getSeqNo())){
            return ResponseInfo.error("序号不能为空!");
        }
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleNo())){
            return ResponseInfo.error("型体不能为空!");
        }
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleColor())){
            return ResponseInfo.error("颜色不能为空!");
        }
        String flag = generalMaterialsMapper.getCheckUp(styleColorDetail.getStyleNo());
        if ("Y".equals(flag)){
            return ResponseInfo.error("该型体已检核,不能添加!");
        }
        UserInfoUtil.UserInfo userInfo = UserInfoUtil.getUserInfo();
        YfStyleColorDetail detail = rAndDUsageMapper.getStyleColorDetail(styleColorDetail.getStyleNo(), styleColorDetail.getStyleColor());
        if (!ObjectUtils.isEmpty(detail)){
            return ResponseInfo.error("该颜色已存在!");
        }
        styleColorDetail.setCompanyId(userInfo.getCompanyId());
        styleColorDetail.setSysUser(userInfo.getLoginName());
        generalMaterialsMapper.addYfStyleColorDetail(styleColorDetail);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 型体配色删除
     * @param styleColorDetail
     * @return
     */
    @Override
    public ResponseInfo getStylePhotoDel(YfStyleColorDetail styleColorDetail) {
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleNo())){
            return ResponseInfo.error("型体不能为空!");
        }
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleColor())){
            return ResponseInfo.error("颜色不能为空!");
        }
        String flag = generalMaterialsMapper.getCheckUp(styleColorDetail.getStyleNo());
        if ("Y".equals(flag)){
            return ResponseInfo.error("该型体已检核,不能删除!");
        }
        YfBomHeadNew2 yfBomHeadNew = largeCargoUsageMapper.getYfBomHeadNew(styleColorDetail.getStyleNo(), styleColorDetail.getStyleColor());
        if (!ObjectUtils.isEmpty(yfBomHeadNew)){
            return ResponseInfo.error("该颜色已关联BOM资料,不能删除!");
        }
        generalMaterialsMapper.delYfStyleColorDetail(styleColorDetail.getStyleNo(),styleColorDetail.getStyleColor());
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 型体配色修改
     * @param styleNo
     * @param styleColor
     * @param styleColorDetail
     * @return
     */
    @Override
    public ResponseInfo getStylePhotoUpdate(String styleNo, String styleColor, YfStyleColorDetail styleColorDetail) {
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleNo())){
            return ResponseInfo.error("型体不能为空!");
        }
        if (ObjectUtils.isEmpty(styleColorDetail.getStyleColor())){
            return ResponseInfo.error("颜色不能为空!");
        }
        String flag = generalMaterialsMapper.getCheckUp(styleColorDetail.getStyleNo());
        if ("Y".equals(flag)){
            return ResponseInfo.error("该型体已检核,不能修改!");
        }
        styleColorDetail.setUpdateUser(UserInfoUtil.getUserInfo().getLoginName());
        generalMaterialsMapper.updateByStyleColorDetail(styleColorDetail);
        return ResponseInfo.ok("操作成功!");
    }
}
